package IC.Error;

public abstract class Error
{
	private boolean _isInLib = false;
	private ErrorType _type;
	public abstract Object Visit(Visitor visitor);
	
	
	protected void SetIsLib(boolean isInLib) { _isInLib = isInLib; } 
	
	public boolean IsInLib() { return _isInLib; }
	
	public ErrorType GetType() { return _type; }
	public void SetType(ErrorType type) { _type = type; }
	
	
	int GetFirstLine() { return -1; }	//for sorting, default if nothing overides it!
	
	static class ErrorComparer implements java.util.Comparator<Error> 
	{
		public int compare(Error o1, Error o2) { return o1.GetFirstLine() - o2.GetFirstLine(); }
	}
	
	public enum ErrorType
	{
		Lexical("Lexical error", 0),
		Parsing("Parsing error", 1),
		Semantic("Semantic error", 2),
		//Why is it 2 not 3... the value in the next line?
		SemanticWarning("Semantic warning", 2),
		CodeGeneration("Code generation error", 4);
		
		private String _string;
		private int _index;
		
		private ErrorType(String string, int index)
		{
			_string = string;
			_index = index;
		}
		
		public String toString() { return new String(_string); }
		public boolean equals(ErrorType type) { return _index == type._index; }
	}
	
	
}
